<template>
	<view class="userLayout pageBg">
		<view class="userInfo">
			<view class="avatar">
				<image :src="userInfo.avatar" mode="aspectFill"></image>
			</view>
			<view class="ip">{{userInfo.nickname}}</view>
			<view class="address">账号：{{userInfo.account}}</view>
		</view>

		<view class="section">
			<view class="list">
				<navigator url="/pages/family/family">
					<view class="row">
						<view class="left">
							<uni-icons type="home" size="20"></uni-icons>
							<view class="text">我的家庭</view>
						</view>
					</view>
				</navigator>

				<navigator url="/pages/myInfo/myInfo">
					<view class="row">
						<view class="left">
							<uni-icons type="star-filled" size="20"></uni-icons>
							<view class="text">个人信息</view>
						</view>
					</view>
				</navigator>

				<view class="row">
					<view class="left">
						<uni-icons type="chatboxes-filled" size="20"></uni-icons>
						<view class="text">联系客服</view>
					</view>
					<view class="right">
						<view class="text"></view>
						<uni-icons type="right" size="15" color="#aaa"></uni-icons>
					</view>
					<!-- #ifdef MP -->
					<button open-type="contact">联系客服</button>
					<!-- #endif -->
					<!-- #ifndef MP -->
					<button @click="clickContact">拨打智慧养老APP客服</button>
					<!-- #endif -->
				</view>
			</view>
		</view>

		<view class="section">
			<view class="list">
				<view class="row" @click="toMonments">
					<view class="left">
						<uni-icons type="notification-filled" size="20"></uni-icons>
						<view class="text">订阅更新</view>
					</view>
					<view class="right">
						<view class="text"></view>
						<uni-icons type="right" size="15" color="#aaa"></uni-icons>
					</view>
				</view>
				<navigator url="/pages/problem/problem">
					<view class="row">
						<view class="left">
							<uni-icons type="flag-filled" size="20"></uni-icons>
							<view class="text">常见问题</view>
						</view>
						<view class="right">
							<view class="text"></view>
							<uni-icons type="right" size="15" color="#aaa"></uni-icons>
						</view>
					</view>
				</navigator>


				<view class="row" @click="outLogin">
					<view class="left">
						<uni-icons type="close" size="20"></uni-icons>
						<view class="text">退出登录</view>
					</view>
					<view class="right">
						<view class="text"></view>
						<uni-icons type="right" size="15" color="#aaa"></uni-icons>
					</view>
				</view>

			</view>
		</view>

	</view>
</template>

<script setup>
	import {
		ref,
		computed,
		onMounted
	} from 'vue'
	import {onShow} from "@dcloudio/uni-app"
	const userInfo = ref('')

	// 页面挂载时自动触发
	onShow(() => {
		setUserInfo()
	})
	const setUserInfo=()=>{
		userInfo.value = uni.getStorageSync('userInfo')
		if(!userInfo.value){
			console.log("为空")
			getUserInfo()
		}
	}
	const getUserInfo = () =>{
		uni.request({
			url:"http://localhost:8081/sysUser/userInfo",
			method: 'GET',
			header: {
			  'Authorization': 'Bearer ' + uni.getStorageSync('token') // 从本地存储获取token
			}
		}).then((res)=>{
			if(res.data.code === '200') {
			    console.log("结果为",res)
				userInfo.value=res.data.result
				uni.setStorageSync('userInfo', res.data.result)
			} else {
				uni.showToast({
					title: res.data.message || '获取用户信息异常',
					icon: 'none'
				})
				
			}
		})
	}
	
	
	
	
	const outLogin = () => {
		uni.clearStorageSync();
		uni.navigateTo({
			url: "/pages/login/login"
		})
	}

	const clickContact = () => {
		uni.makePhoneCall({
			phoneNumber: "12345"
		})
	}

	const toMonments = () => {
		uni.switchTab({
			url: '/pages/moments/moments'
		})
	}
</script>

<style lang="scss" scoped>
	.userLayout {
		.userInfo {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			padding: 50rpx 0;

			.avatar {
				width: 160rpx;
				height: 160rpx;
				border-radius: 50%;
				overflow: hidden;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.ip {
				font-size: 44rpx;
				color: #333;
				padding: 20rpx 0 5rpx;
			}

			.address {
				font-size: 28rpx;
				color: #aaa;
			}
		}

		.section {
			width: 690rpx;
			margin: 50rpx auto;
			border: 1px solid #eee;
			border-radius: 10rpx;
			box-shadow: 0 0 30rpx rgba(0, 0, 0, 0.05);

			.list {
				.row {
					display: flex;
					// 左右布局的
					justify-content: space-between;
					align-items: center;
					padding: 0 30rpx;
					height: 100rpx;
					border-bottom: 1px solid #eee;
					position: relative;
					background: #fff;

					&:last-child {
						border-bottom: 0
					}

					.left {
						display: flex;
						align-items: center;

						:deep() {
							.uni-icons {
								color: $brand-theme-color !important;
							}
						}

						.text {
							padding-left: 20rpx;
							color: #666
						}
					}

					.right {
						display: flex;
						align-items: center;

						.text {
							font-size: 28rpx;
							color: #aaa;

						}
					}

					button {
						position: absolute;
						top: 0;
						left: 0;
						height: 100rpx;
						width: 100%;
						opacity: 0;
					}
				}
			}
		}
	}
</style>